#include <STC15F2K60S2.H>
#include "juzhen.h"
#include "smg.h"
#include "Timer0.h"

#define uchar unsigned char

uchar keynum;

void main()
{
	P2 = 0xA0; P0 = 0x00; P2 = 0xC0; P0 = 0xFF;	P2 = 0xFF;	//初始化,P0控制数码管
	Timer0_Init();
	while(1)
	{
		keynum = KeyJZ_16();
		
		if     (keynum == 7)	P0 = tab[1];
		else if (keynum == 11)	P0 = tab[2];
		else if (keynum == 15)	P0 = tab[3];
		else if (keynum == 19)	P0 = tab[4];
		else if (keynum == 6)	P0 = tab[5];
		else if (keynum == 10)	P0 = tab[6];
		else if (keynum == 14)	P0 = tab[7];
		else if (keynum == 18)	P0 = tab[8];
		else if (keynum == 5)	P0 = tab[9];
		else if (keynum == 9)	P0 = tab[0];
		else if (keynum == 13)	P0 = tab[10];
		else if (keynum == 17)	P0 = tab[11];
		else if (keynum == 4)	P0 = tab[12];
		else if (keynum == 8)	P0 = tab[13];
		else if (keynum == 12)	P0 = tab[14];
		else if (keynum == 16)	P0 = tab[15];	
	}
}


void Timer0_Rountine(void) interrupt 1
{
	static unsigned int Count0;
	static unsigned char i = 0;
	
//  自动重载，不用加这两句了	
//	TL0 = 0x00;		//设置定时初始值
//	TH0 = 0x28;		//设置定时初始值
	
	Count0++;
	if(Count0 >= 200)	//200*5ms = 1s
	{
		P0 = tab[i];
		i++;
		if(i>=18) i = 0;	//越界复位
		Count0 = 0;	//软件复位
	}
}
